package com.duolaibei.business.view.activity;

import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.support.v4.widget.NestedScrollView;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.ScrollView;
import android.widget.TextView;

import com.duolaibei.business.R;
import com.duolaibei.business.api.ApiName;
import com.duolaibei.business.base.BaseActivity;
import com.duolaibei.business.config.Preferences;
import com.duolaibei.business.http.HttpUtils;
import com.duolaibei.business.model.OrderListData;
import com.duolaibei.business.model.ResponseResult;
import com.duolaibei.business.utils.ACache;
import com.duolaibei.business.utils.CommonUtil;
import com.duolaibei.business.utils.DlbPrintUtil;
import com.duolaibei.business.utils.GsonUtil;
import com.duolaibei.business.utils.PreferenceUtil;
import com.duolaibei.business.utils.inject.Inject;
import com.duolaibei.business.utils.log.LogDebug;
import com.duolaibei.business.view.App;
import com.duolaibei.business.view.dialog.PasswordDialog;
import com.duolaibei.business.view.dialog.TipDialog;
import com.duolaibei.business.widget.DividerLine;
import com.scwang.smartrefresh.layout.SmartRefreshLayout;
import com.scwang.smartrefresh.layout.api.RefreshLayout;
import com.scwang.smartrefresh.layout.listener.OnLoadmoreListener;
import com.scwang.smartrefresh.layout.listener.OnRefreshListener;
import com.zhy.adapter.recyclerview.CommonAdapter;
import com.zhy.adapter.recyclerview.base.ViewHolder;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by xlm on 2017/11/4 0004
 */

public class OrderListActivity extends BaseActivity {

    @Inject(R.id.reset)
    private RelativeLayout mLayoutReset;
    @Inject(R.id.search)
    private RelativeLayout mLayoutSearchBtn;
    @Inject(R.id.search_order_recycle)
    private RecyclerView mRecyclerViewSearch;
    @Inject(R.id.search_order_refresh)
    private SmartRefreshLayout mRefreshLayout;

    private int pagesize = 5;
    private int pagenum = 1;

    private static final int MODE_QUERY = 1;
    private static final int MODE_REFRESH = 2;
    private static final int MODE_MORE = 3;

    private static int CURRENT_MODE = MODE_QUERY;

    private static List<OrderListData.DataBeanX.DataBean> mOrderList;
    private List<OrderListData.DataBeanX.DataBean> mOrderListNew;
    private CommonAdapter<OrderListData.DataBeanX.DataBean> mCommonAdapter;//适配器
    @Inject(R.id.serarch_order_time)
    private TextView time;
    @Inject(R.id.search_transaction_amount)
    private TextView amount;
    @Inject(R.id.search_transaction_num)
    private TextView num;
    @Inject(R.id.order_count)
    private LinearLayout mLayout;
    @Inject(R.id.back)
    private RelativeLayout mLayoutBack;
    @Inject(R.id.title)
    private TextView mTextViewTitle;
    @Inject(R.id.order_srollview)
    private NestedScrollView mNestedScrollView;

    private String type;
    private String shopId;
    private String begintime;
    private String endtime;
    private String state;
    private String tradeNum;

    @Override
    protected void onGetIntent(Intent intent) {
        super.onGetIntent(intent);
        if (intent != null) {
            type = intent.getStringExtra("order_type");
        }
    }

    @Override
    protected void onSetContentView() {
        setContentView(R.layout.activity_order_list);
    }

    @Override
    protected void initViews() {
        mTextViewTitle.setText("订单列表");
    }

    @Override
    protected void afterOnCreate(Bundle savedInstanceState) {
        if ("all".equals(type)) {
            getOrderData();
            mLayoutReset.setVisibility(View.GONE);
            mLayoutSearchBtn.setVisibility(View.VISIBLE);
        } else {
            mLayoutReset.setVisibility(View.VISIBLE);
            mLayoutSearchBtn.setVisibility(View.GONE);
        }
        setAdapterData();
    }

    @Override
    protected void onSetListener() {
        mLayoutReset.setOnClickListener(this);
        mLayoutBack.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
        mRefreshLayout.setOnRefreshListener(new OnRefreshListener() {
            @Override
            public void onRefresh(RefreshLayout refreshlayout) {
                onRefreshData();
            }
        });
        mRefreshLayout.setOnLoadmoreListener(new OnLoadmoreListener() {
            @Override
            public void onLoadmore(RefreshLayout refreshlayout) {
                if (mOrderListNew.size() == pagesize) {
                    pagenum++;
                    CURRENT_MODE = MODE_MORE;
                    getOrderData();
                } else {
                    mRefreshLayout.setEnableLoadmore(false);
                }
            }
        });
        //查单
        mLayoutSearchBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent();
                intent.setClass(getThis(), SearchOrderActivity.class);
                startActivityForResult(intent, 1);
            }
        });
    }

    /**
     * 刷新列表界面
     */
    private void onRefreshData() {
        pagenum = 1;
        CURRENT_MODE = MODE_REFRESH;
        getOrderData();
    }

    /**
     * 设置适配器信息
     */
    private void setAdapterData() {
        mOrderList = new ArrayList<>();
        mCommonAdapter = new CommonAdapter<OrderListData.DataBeanX.DataBean>(getThis(),
                R.layout.item_order_content,
                mOrderList) {
            @Override
            protected void convert(ViewHolder holder, final OrderListData.DataBeanX.DataBean dataBean,
                                   int position) {
                LogDebug.d(dataBean.getStatusX());
                holder.setText(R.id.order_introduce, String.format(getString(R.string._2_s), dataBean.getBody()));
                if ("0".equals(dataBean.getStatusX())) {
                    holder.setTextColor(R.id.order_status, Color.parseColor("#9D9D9D"));
                    holder.setText(R.id.order_status, "未支付");
                    holder.getView(R.id.order_print).setVisibility(View.GONE);
                    holder.getView(R.id.order_drawback).setVisibility(View.GONE);
                    holder.getView(R.id.order_synchro).setVisibility(View.VISIBLE);
                    holder.getView(R.id.order_synchro).setOnClickListener(new View.OnClickListener() {
                        @Override
                        public void onClick(View v) {
                            //同步 刷新列表信息
                            syncData(dataBean.getOut_trade_no());
                        }
                    });
                } else if ("1".equals(dataBean.getStatusX())) {
                    holder.setTextColor(R.id.order_status, Color.parseColor("#259B24"));
                    holder.setText(R.id.order_status, "已收款");
                    holder.getView(R.id.order_print).setVisibility(View.VISIBLE);
                    holder.getView(R.id.order_drawback).setVisibility(View.VISIBLE);
                    holder.getView(R.id.order_synchro).setVisibility(View.GONE);
                    holder.getView(R.id.order_print).setOnClickListener(new View.OnClickListener() {
                        @Override
                        public void onClick(View v) {
                            //打印次数
                            final int printCount = Integer.valueOf(String.valueOf(
                                    PreferenceUtil.getParam(Preferences.PRINTNUM, "")));
                            if ("true".equals(String.valueOf(PreferenceUtil.getParam(Preferences.ISCONNECTED, "")))) {
                                //开始打印
                                try {
                                    DlbPrintUtil.printListData(getThis(), dataBean,
                                            String.valueOf(dataBean.getOut_trade_no())
                                            , printCount);
                                } catch (Exception e) {
                                    e.printStackTrace();
                                }
                            } else {
                                showToast("请先连接打印机");
                            }
                        }
                    });
                    holder.getView(R.id.order_drawback).setOnClickListener(new View.OnClickListener() {
                        @Override
                        public void onClick(View v) {
                            //退款
                            showPasswordDialog(dataBean);
//                            showConfirm("退款确认", "请点击确认按钮完成退款", dataBean);
                        }
                    });
                } else if ("-1".equals(dataBean.getStatusX())) {
                    holder.setTextColor(R.id.order_status, Color.parseColor("#B3000B"));
                    holder.setText(R.id.order_status, "已退款");
                    holder.getView(R.id.order_print).setVisibility(View.GONE);
                    holder.getView(R.id.order_drawback).setVisibility(View.GONE);
                    holder.getView(R.id.order_synchro).setVisibility(View.GONE);
                }
                holder.setText(R.id.order_amount, String.format(getString(R.string._3_s), dataBean.getTotal_amount()));
                holder.setText(R.id.order_real_amount, String.format(getString(R.string._4_s), dataBean.getPay_amount()));
                holder.setText(R.id.order_beigin, String.format(getString(R.string._5_s),
                        CommonUtil.formatDate(Long.valueOf(dataBean.getAddtime()) * 1000,
                                "yyyy-MM-dd HH:mm:ss")));
                if ("0".equals(dataBean.getPaytime())) {
                    holder.setText(R.id.order_complete, String.format(getString(R.string._6_s), ""
                    ));
                } else {
                    holder.setText(R.id.order_complete, String.format(getString(R.string._6_s),
                            CommonUtil.formatDate(Long.valueOf(dataBean.getPaytime()) * 1000,
                                    "yyyy-MM-dd HH:mm:ss")));
                }
                holder.setText(R.id.order_type, String.format(getString(R.string._7_s), dataBean.getPay_name()));
                holder.setText(R.id.order_orderid, String.format(getString(R.string._8_s), dataBean.getOut_trade_no()));
                holder.setText(R.id.order_comment, String.format(getString(R.string._9_s), dataBean.getRemark()));
            }
        };
        mRecyclerViewSearch.setLayoutManager(new LinearLayoutManager(getThis()));
        mRecyclerViewSearch.setNestedScrollingEnabled(false);
        DividerLine dividerLine = new DividerLine(DividerLine.VERTICAL);
        dividerLine.setSize(2);
        dividerLine.setColor(getResources().getColor(R.color.divider_line));
        mRecyclerViewSearch.addItemDecoration(dividerLine);
        mRecyclerViewSearch.setAdapter(mCommonAdapter);
    }

    private void setOrdersData(String string, boolean save) {
        final OrderListData notesData = GsonUtil.GsonToBean(string, OrderListData.class);
        List<OrderListData.DataBeanX.DataBean> dataBeanList = notesData.getData().getData();
        mOrderListNew = dataBeanList;
        if (CURRENT_MODE != MODE_MORE) {
            mOrderList.clear();
        }
        if (dataBeanList.size() != 0) {
            mOrderList.addAll(dataBeanList);
        } else {
            mRefreshLayout.setEnableLoadmore(false);
        }
        if (save) {
            try {
                String json = GsonUtil.GsonString(mOrderList);
                JSONObject jsonObject = new JSONObject(string);
                JSONObject jsonObject1 = jsonObject.optJSONObject("data");
                JSONArray jsonArray = new JSONArray(json);
                jsonObject1.put("data", jsonArray);
                ACache.get(App.getApp()).put(ApiName.ORDER, jsonObject);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        runOnUiThread(new Runnable() {
            @Override
            public void run() {
                mNestedScrollView.fullScroll(ScrollView.FOCUS_UP);
                mCommonAdapter.notifyDataSetChanged();
                time.setText(String.format(getString(R.string._1_s), CommonUtil.formatDate(
                        Long.valueOf(notesData.getData().getStart_time()) * 1000,
                        "yyyy-MM-dd HH:mm:ss")) + " - " +
                        CommonUtil.formatDate(Long.valueOf(notesData.getData().getEnd_time()) * 1000,
                                "yyyy-MM-dd HH:mm:ss"));//统计时间
                amount.setText(String.valueOf(notesData.getData().getPay_amount()));//金额
                num.setText(String.valueOf(notesData.getData().getCount()));//笔数
                mLayout.setVisibility(View.VISIBLE);
            }
        });
    }

    /**
     * 获取订单列表信息
     */
    private void getOrderData() {
        HttpUtils.RequestParam param = new HttpUtils.RequestParam();
        param.add("method", ApiName.ORDER);
        param.add("uid", String.valueOf(PreferenceUtil.getParam(Preferences.UID, "")));
        param.add("login_type", String.valueOf(PreferenceUtil.getParam(Preferences.LOGINTYPE, "")));
        param.add("login_id", String.valueOf(PreferenceUtil.getParam(Preferences.LOGINID, "")));
        if ("part".equals(type)) {
            if (!CommonUtil.isEmpty(state)) {
                param.add("order_status", state);
            } else if (!CommonUtil.isEmpty(shopId)) {
                param.add("shop_id", shopId);
            } else if (!CommonUtil.isEmpty(begintime)) {
                param.add("start_time", begintime);
            } else if (!CommonUtil.isEmpty(endtime)) {
                param.add("end_time", endtime);
            } else if (!CommonUtil.isEmpty(tradeNum)) {
                param.add("out_trade_no", tradeNum);
            }
            mLayout.setVisibility(View.GONE);
        }
        param.add("current_page", String.valueOf(pagenum));
        param.add("page_size", String.valueOf(pagesize));
        param.add("sign", param.getMd5String());
        showLoading("加载中");
        HttpUtils.getInstance().url(ApiName.API).params(param).executePost(new HttpUtils.HttpListener() {
            @Override
            public void onException(Throwable e) {
                super.onException(e);
                dismissLoading();
                if (CommonUtil.isForeground(getThis())) {
                    showToast(getString(R.string.net_state));
                    String jsonString = ACache.get(App.getApp()).getAsString(ApiName.ORDER);
                    if (!CommonUtil.isEmpty(jsonString)) {
                        mOrderList.clear();
                        setOrdersData(jsonString, false);
                    }
                }
                if (mOrderListNew.size() == pagesize) {
                    mRefreshLayout.setEnableLoadmore(true);
                } else {
                    mRefreshLayout.setEnableLoadmore(false);
                }
                switch (CURRENT_MODE) {
                    case MODE_QUERY:
                        break;
                    case MODE_REFRESH:
                        mRefreshLayout.finishRefresh(false);
                        break;
                    case MODE_MORE:
                        mRefreshLayout.finishLoadmore(false);
                        break;
                }
            }

            @Override
            public void onHttpSuccess(String string) {
                super.onHttpSuccess(string);
                dismissLoading();
                if (HttpUtils.isJson(string)) {
                    ResponseResult responseResult = GsonUtil.GsonToBean(string, ResponseResult.class);
                    if (responseResult.getStatus() == 1) {
                        if ("part".equals(type)) {
                            showToast(responseResult.getInfo());
                        }
                        setOrdersData(string, false);
                    } else {
                        showToast(responseResult.getInfo());
                        mRefreshLayout.setEnableLoadmore(false);
                    }
                } else {
                    mRefreshLayout.setEnableLoadmore(false);
                }
                switch (CURRENT_MODE) {
                    case MODE_QUERY:
                        break;
                    case MODE_REFRESH:
                        mRefreshLayout.finishRefresh(true);
                        break;
                    case MODE_MORE:
                        mRefreshLayout.finishLoadmore(true);
                        break;
                }
                if (mOrderListNew.size() == pagesize) {
                    mRefreshLayout.setEnableLoadmore(true);
                } else {
                    mRefreshLayout.setEnableLoadmore(false);
                }
            }
        });
    }

    private TipDialog confirmDialog;

    private void showConfirm(String title, String content, final OrderListData.DataBeanX.DataBean dataBean) {
        if (confirmDialog == null) {
            confirmDialog = new TipDialog(getThis());
        }
        confirmDialog.setTitle(title);
        confirmDialog.setContent(content);
        confirmDialog.setCancelable(true);
        confirmDialog.setConfirm("确认");
        //设置为系统弹窗，任何位置都可以弹出
        //confirmDialog.getWindow().setType(WindowManager.LayoutParams.TYPE_TOAST);
        confirmDialog.show();
        confirmDialog.setListener(new TipDialog.Listener() {
            @Override
            public void onConfirm() {
                super.onConfirm();
                confirmDialog.dismiss();
                showPasswordDialog(dataBean);
            }

            @Override
            public void onDismiss() {
                super.onDismiss();
                confirmDialog.dismiss();
            }
        });
    }

    private PasswordDialog passwordDialog;

    private void showPasswordDialog(final OrderListData.DataBeanX.DataBean dataBean) {
        if (passwordDialog == null) {
            passwordDialog = new PasswordDialog(this);
        }
        passwordDialog.setCancelable(true);
        passwordDialog.show();
        passwordDialog.setListener(new PasswordDialog.Listener() {
            @Override
            public void onConfirm(String ps) {
                if (CommonUtil.isEmpty(ps)) {
                    showToast("请输入登陆密码");
                } else {
                    String password = (String) PreferenceUtil.getParam(Preferences.PASSWORD, "");
                    if (!CommonUtil.isEmpty(password) && !password.equals(ps)) {
                        showToast("密码错误");
                    } else {
                        passwordDialog.dismiss();
                        refundOrder(dataBean);
                    }
                }
            }
        });
    }

    /**
     * 订单退款
     */
    private void refundOrder(OrderListData.DataBeanX.DataBean dataBean) {
        HttpUtils.RequestParam param = new HttpUtils.RequestParam();
        param.add("method", ApiName.REFUND);
        param.add("uid", String.valueOf(PreferenceUtil.getParam(Preferences.UID, "")));
        param.add("login_type", String.valueOf(PreferenceUtil.getParam(Preferences.LOGINTYPE, "")));
        param.add("out_trade_no", String.valueOf(dataBean.getOut_trade_no()));
        param.add("sign", param.getMd5String());
        showLoading("处理中");
        HttpUtils.getInstance().url(ApiName.API).params(param).executePost(new HttpUtils.HttpListener() {
            @Override
            public void onException(Throwable e) {
                super.onException(e);
                dismissLoading();
                if (CommonUtil.isForeground(getThis())) {
                    showToast(getString(R.string.net_state));
                }
            }

            @Override
            public void onHttpSuccess(final String string) {
                super.onHttpSuccess(string);
                dismissLoading();
                if (HttpUtils.isJson(string)) {
                    ResponseResult result = GsonUtil.GsonToBean(string, ResponseResult.class);
                    showToast(result.getInfo());
                    if (result.getStatus() == 1) {
                        //退款成功
                        runOnUiThread(new Runnable() {
                            @Override
                            public void run() {
                                Message message = null;
                                try {
                                    JSONObject object = new JSONObject(string);
                                    JSONObject object1 = object.getJSONObject("data");
                                    message = Message.obtain();
                                    message.what = 111;
                                    message.obj = object1.optString("out_trade_no");
                                } catch (JSONException e) {
                                    e.printStackTrace();
                                }
                                mHandler.sendMessage(message);
                            }
                        });
                        showLoading("退款成功");
                    }
                } else {
                    showToast(string);
                }
                new Handler(getMainLooper()).postDelayed(new Runnable() {
                    @Override
                    public void run() {
                        dismissLoading();
                    }
                }, 1000);
            }
        });
    }

    /**
     * 订单同步
     */
    private void syncData(String tradeNum) {
        HttpUtils.RequestParam param = new HttpUtils.RequestParam();
        param.add("method", ApiName.SYNC);
        param.add("uid", String.valueOf(PreferenceUtil.getParam(Preferences.UID, "")));
        param.add("login_type", String.valueOf(PreferenceUtil.getParam(Preferences.LOGINTYPE, "")));
        param.add("out_trade_no", tradeNum);
        param.add("sign", param.getMd5String());
        showLoading("处理中");
        HttpUtils.getInstance().url(ApiName.API).params(param).executePost(new HttpUtils.HttpListener() {
            @Override
            public void onException(Throwable e) {
                super.onException(e);
                dismissLoading();
                if (CommonUtil.isForeground(getThis())) {
                    showToast(getString(R.string.net_state));
                }
            }

            @Override
            public void onHttpSuccess(final String string) {
                super.onHttpSuccess(string);
                dismissLoading();
                if (HttpUtils.isJson(string)) {
                    ResponseResult result = GsonUtil.GsonToBean(string, ResponseResult.class);
                    showToast(result.getInfo());
                    if (result.getStatus() == 1) {
                        //退款成功
                        runOnUiThread(new Runnable() {
                            @Override
                            public void run() {
                                Message message = null;
                                try {
                                    JSONObject object = new JSONObject(string);
                                    JSONObject object1 = object.getJSONObject("data");
                                    String introduce = object1.optString("body");
                                    String status = object1.optString("status");
                                    String amount = object1.optString("total_amount");
                                    String real_amount = object1.optString("pay_amount");
                                    String addtime = object1.optString("addtime");
                                    String paytime = object1.optString("paytime");
                                    String paytype = object1.optString("pay_type");
                                    String tradenum = object1.optString("out_trade_no");
                                    String comment = object1.optString("remark");
                                    OrderData orderData = new OrderData(introduce,
                                            status,
                                            amount,
                                            real_amount,
                                            addtime,
                                            paytime,
                                            paytype,
                                            tradenum,
                                            comment
                                    );
                                    message = Message.obtain();
                                    message.what = 222;
                                    message.obj = orderData;
                                } catch (JSONException e) {
                                    e.printStackTrace();
                                }
                                mHandler.sendMessage(message);
                            }
                        });
                    }
                } else {
                    showToast(string);
                }
            }
        });
    }

    //同步和退款操作
    Handler mHandler = new Handler() {
        @Override
        public void handleMessage(Message msg) {
            super.handleMessage(msg);
            //退款操作
            if (msg.what == 111) {
                //可视范围内  item的具体下标(非回收后的)
                //首次 -1  -1
                int start = ((LinearLayoutManager) mRecyclerViewSearch.getLayoutManager())
                        .findFirstVisibleItemPosition();
                int end = ((LinearLayoutManager) mRecyclerViewSearch.getLayoutManager())
                        .findLastVisibleItemPosition();
                //mListView.getChildCount()
                //可视范围内的数量
                for (int i = 0; i < mRecyclerViewSearch.getChildCount(); i++) {
                    if (start == -1) {
                        continue;
                    }
                    if (start >= end) {
                        if (start != 0) {
                            break;
                        }
                    }
                    ViewGroup parent = (ViewGroup) mRecyclerViewSearch.getChildAt(i);
                    TextView orderid = (TextView) parent.findViewById(R.id.order_orderid);
                    String order_id = orderid.getText().toString();
                    if (String.valueOf(msg.obj).equals(order_id.substring(order_id.indexOf("：") + 1
                            , order_id.length()))) {
                        LogDebug.d(String.valueOf(msg.obj));
                        LogDebug.d(order_id.substring(order_id.indexOf("：") + 1
                                , order_id.length()));
                        TextView refund = (TextView) parent.findViewById(R.id.order_status);
                        TextView print = (TextView) parent.findViewById(R.id.order_print);
                        TextView drawback = (TextView) parent.findViewById(R.id.order_drawback);
                        TextView synchro = (TextView) parent.findViewById(R.id.order_synchro);
                        TextView amount = (TextView) parent.findViewById(R.id.order_real_amount);
                        amount.setText(String.format(getString(R.string._4_s), "0.00"));
                        refund.setText("已退款");
                        refund.setTextColor(Color.parseColor("#B3000B"));
                        print.setVisibility(View.GONE);
                        drawback.setVisibility(View.GONE);
                        synchro.setVisibility(View.GONE);
                        break;
                    }
                    start++;
                }
                //同步操作
            } else if (msg.what == 222) {
                //可视范围内  item的具体下标(非回收后的)
                //首次 -1  -1
                int start = ((LinearLayoutManager) mRecyclerViewSearch.getLayoutManager())
                        .findFirstVisibleItemPosition();
                int end = ((LinearLayoutManager) mRecyclerViewSearch.getLayoutManager())
                        .findLastVisibleItemPosition();
                OrderData orderData = (OrderData) msg.obj;
                //mListView.getChildCount()
                //可视范围内的数量
                for (int i = 0; i < mRecyclerViewSearch.getChildCount(); i++) {
                    if (start == -1) {
                        continue;
                    }
                    if (start >= end) {
                        if (start != 0) {
                            break;
                        }
                    }

                    ViewGroup parent = (ViewGroup) mRecyclerViewSearch.getChildAt(i);
                    TextView orderid = (TextView) parent.findViewById(R.id.order_orderid);
                    String order_id = orderid.getText().toString();
                    if (orderData.getTradenum().equals(order_id.substring(order_id.indexOf("：") + 1
                            , order_id.length()))) {
                        //订单未支付  状态不变
                        if ("0".equals(orderData.getStatus())) {
                            return;
                        }

                        TextView refund = (TextView) parent.findViewById(R.id.order_status);
                        refund.setText("已收款");
                        refund.setTextColor(Color.parseColor("#259B24"));

                        TextView print = (TextView) parent.findViewById(R.id.order_print);
                        TextView drawback = (TextView) parent.findViewById(R.id.order_drawback);
                        TextView synchro = (TextView) parent.findViewById(R.id.order_synchro);

                        print.setVisibility(View.VISIBLE);
                        drawback.setVisibility(View.VISIBLE);
                        synchro.setVisibility(View.GONE);

                        print.setOnClickListener(new View.OnClickListener() {
                            @Override
                            public void onClick(View v) {

                            }
                        });

                        drawback.setOnClickListener(new View.OnClickListener() {
                            @Override
                            public void onClick(View v) {
                                //退款
                            }
                        });

                        break;
                    }
                    start++;
                }
            }
        }
    };


    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (resultCode == RESULT_OK) {
            if (requestCode == 1) {
                shopId = data.getStringExtra("shopId");
                begintime = data.getStringExtra("begintime");
                endtime = data.getStringExtra("endtime");
                state = data.getStringExtra("state");
                tradeNum = data.getStringExtra("tradeNum");
                type = "part";
                pagesize = 5;
                pagenum = 1;
                getOrderData();
                if ("part".equals(type)) {
                    mLayoutReset.setVisibility(View.VISIBLE);
                    mLayoutSearchBtn.setVisibility(View.GONE);
                    mLayoutReset.setOnClickListener(new View.OnClickListener() {
                        @Override
                        public void onClick(View v) {
                            type = "all";
                            mLayoutReset.setVisibility(View.GONE);
                            mLayoutSearchBtn.setVisibility(View.VISIBLE);
                            onRefreshData();
                        }
                    });
                }
            }
        }
    }

    private class OrderData {
        String introduce;
        String status;
        String amount;
        String real_amount;
        String addtime;
        String paytime;
        String paytype;
        String tradenum;
        String comment;

        public OrderData(String introduce,
                         String status,
                         String amount,
                         String real_amount,
                         String addtime,
                         String paytime,
                         String paytype,
                         String tradenum,
                         String comment) {
            this.introduce = introduce;
            this.status = status;
            this.amount = amount;
            this.real_amount = real_amount;
            this.addtime = addtime;
            this.paytime = paytime;
            this.paytype = paytype;
            this.tradenum = tradenum;
            this.comment = comment;
        }

        public String getIntroduce() {
            return introduce;
        }

        public void setIntroduce(String introduce) {
            this.introduce = introduce;
        }

        public String getStatus() {
            return status;
        }

        public void setStatus(String status) {
            this.status = status;
        }

        public String getAmount() {
            return amount;
        }

        public void setAmount(String amount) {
            this.amount = amount;
        }

        public String getReal_amount() {
            return real_amount;
        }

        public void setReal_amount(String real_amount) {
            this.real_amount = real_amount;
        }

        public String getAddtime() {
            return addtime;
        }

        public void setAddtime(String addtime) {
            this.addtime = addtime;
        }

        public String getPaytime() {
            return paytime;
        }

        public void setPaytime(String paytime) {
            this.paytime = paytime;
        }

        public String getPaytype() {
            return paytype;
        }

        public void setPaytype(String paytype) {
            this.paytype = paytype;
        }

        public String getTradenum() {
            return tradenum;
        }

        public void setTradenum(String tradenum) {
            this.tradenum = tradenum;
        }

        public String getComment() {
            return comment;
        }

        public void setComment(String comment) {
            this.comment = comment;
        }
    }


}
